import { ClickBuriedProps } from '@/util/buried'
import { create } from 'zustand'

/**
 * 埋点信息，用于多个页面触发同一接口的情况
 */

type buriedState = {
  buriedInfo: ClickBuriedProps
  putAstBuriedCount: number // 智能体页面/api/v1/assistant接口埋点计数
  putAstBuriedCurCount: number // 智能体页面/api/v1/assistant接口已埋点计数
}

type Actions = {
  updateBuriedInfo: (buriedInfo: ClickBuriedProps) => void
  updatePutAstBuriedCount: () => void
  updatePutAstBuriedCurCount: () => void
}

export const useBuriedStore = create<buriedState & Actions>(set => ({
  buriedInfo: {
    event_name: ''
  },
  putAstBuriedCount: 0,
  putAstBuriedCurCount: 0,
  updateBuriedInfo: buriedInfo => set({ buriedInfo: { ...buriedInfo } }),
  updatePutAstBuriedCount: () =>
    set(state => {
      return { putAstBuriedCount: state.putAstBuriedCount + 1 }
    }),
  updatePutAstBuriedCurCount: () =>
    set(state => {
      return { putAstBuriedCurCount: state.putAstBuriedCurCount + 1 }
    })
}))
